var t = require("../../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Component({
    properties: {
        params: {
            type: null
        },
        data: {
            type: null
        }
    },
    data: {
        language: "",
        coupon_list: []
    },
    lifetimes: {
        attached: function() {
            var t = wx.getStorageSync("langIndex");
            this.setData({
                language: t.en
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        "0" == this.data.params.addmethod ? this.autoGetData() : this.setData({
            coupon_list: this.data.data
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        autoGetData: function() {
            var t = this, a = e.getNetAddresss("coupon.member-coupon.coupons-for-designer");
            e._getNetWork({
                showToastIn: !1,
                url: a,
                success: function(e) {
                    var a = e.data;
                    1 == a.result && t.setData({
                        coupon_list: a.data.data
                    });
                },
                fail: function(t) {}
            });
        },
        selectedcoupon: function(a) {
            var o = a.currentTarget.dataset.index, n = a.currentTarget.dataset.item;
            if (3 != n.api_availability) {
                var s = this, i = e.getNetAddresss("coupon.member-coupon.get-coupon");
                i += "&coupon_id=" + n.coupon_id, e._getNetWork({
                    showToastIn: !1,
                    url: i,
                    success: function(e) {
                        var a = e.data;
                        if (1 == a.result) {
                            var n = a.data;
                            s.setData(t({}, "coupon_list[" + o + "]", n)), wx.showToast({
                                icon: "none",
                                title: "优惠券领取成功",
                                duration: 1500
                            });
                        } else a.data.reason ? wx.showModal({
                            title: a.msg,
                            content: a.data.reason,
                            showCancel: !1
                        }) : wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 1e3
                        });
                    },
                    fail: function(t) {}
                });
            }
        }
    }
});